package collection;

import java.util.*;

public class Work1 {
    public static void main(String[] args) {
        /*
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list);

        String e = list.get(2);
        System.out.println(e);

        String old = list.set(3,"six");
        System.out.println("list:"+list);
        System.out.println(old);

        list.remove(2);
        System.out.println("list:"+list);

        list.add(3,"seven");
        System.out.println("list:"+list);

        List<Integer> list1 = new ArrayList<>();
        for (int i = 0;i<10;i++){
            list1.add(i*10);
        }
        System.out.println("list1:"+list1);

        List<Integer> sublist = list1.subList(3,8);
        System.out.println("sublist:"+sublist);

        for (int i = 0;i< sublist.size();i++){
            sublist.set(i, sublist.get(i)*10);
        }
        System.out.println("乘十倍sublist:"+sublist);

        Random rand = new Random();
        List<Integer> list2 = new ArrayList<>();
        for (int i = 0;i<10;i++){
            list2.add(rand.nextInt(100));
        }
        System.out.println("list2原始数据:"+list2);
        Collections.sort(list2);
        System.out.println("list2排序后数据:"+list2);


        List<String> list3 = new ArrayList<>();
        list3.add("王克晶");
        list3.add("传奇saaaaafd");
        list3.add("国斌老师");
        System.out.println("list3原始数据:"+list3);
        Collections.sort(list3, new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });
        System.out.println("list3排序后数据:"+list3);

        List<Point> list4 = new ArrayList<>();
        list4.add(new Point(5,8));
        list4.add(new Point(15,60));
        list4.add(new Point(57,89));
        list4.add(new Point(1,4));
        list4.add(new Point(10,8));
        list4.add(new Point(22,35));
        System.out.println("list4原始数据:"+list4);
        Collections.sort(list4,(o1, o2) -> {
            int len1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
            int len2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
            return len1-len2;
        });
        System.out.println("list4排序后数据:"+list4);

        List<String> list5 = new ArrayList<>();
        list5.add("one");
        list5.add("two");
        list5.add("three");
        list5.add("four");
        list5.add("five");
        list5.add("two");
        System.out.println("list5:"+list5);

        Set<String> set = new HashSet<>();
        set.addAll(list5);
        System.out.println("set:"+set);

         */

        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list);
        list.get(2);
        System.out.println("list:"+list);
        list.set(3,"six");
        System.out.println("list:"+list);
        list.remove(4);
        System.out.println("list:"+list);
        list.add(3,"seven");
        System.out.println("list:"+list);

        List<Integer> list1 = new ArrayList<>();
        for (int i =0;i<10;i++){
            list1.add(i*10);
        }
        System.out.println("list1:"+list1);
        List<Integer> sublist = list1.subList(3,8);
        System.out.println("sublist:"+sublist);
        for (int i = 0;i< sublist.size();i++){
            sublist.set(i, sublist.get(i)*10);
        }
        System.out.println("sublist十倍:"+sublist);

        Random rand = new Random();
        List<Integer> list2 = new ArrayList<>();
        for (int i = 0;i<10;i++){
            list2.add(rand.nextInt(100) );
        }
        System.out.println("list2原始数据:"+list2);
        Collections.sort(list2);
        System.out.println("list2排序后数据:"+list2);

        List<String> list3 = new ArrayList<>();
        list3.add("王克晶");
        list3.add("传奇asdghasd");
        list3.add("国斌老师");
        System.out.println("list3原始数据:"+list3);
        Collections.sort(list3, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });
        System.out.println("list3排序后数据:"+list3);

        List<Point> list4 = new ArrayList<>();
        list4.add(new Point(5,8));
        list4.add(new Point(15,60));
        list4.add(new Point(57,89));
        list4.add(new Point(1,4));
        list4.add(new Point(10,8));
        list4.add(new Point(22,35));
        System.out.println("list4原始数据:"+list4);
        Collections.sort(list4,(o1, o2) -> {
            int len1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
            int len2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
            return len1-len2;
        });
        System.out.println("list排序后数据:"+list4);

        List<String> list5 = new ArrayList<>();
        list5.add("one");
        list5.add("two");
        list5.add("three");
        list5.add("four");
        list5.add("five");
        list5.add("two");
        System.out.println("list5:"+list5);

        Set<String> set = new HashSet<>();
        set.addAll(list5);
        System.out.println("set:"+set);
    }
}
